import openpyxl

image_urls = [
    "https://so1.360tres.com/t0165f9b1a3dca6c254.jpg",
    "https://so1.360tres.com/t0165f9b1a3dca6c254.jpg",
    "https://so1.360tres.com/t0165f9b1a3dca6c254.jpg",
    "https://so1.360tres.com/t0165f9b1a3dca6c254.jpg",
    "https://so1.360tres.com/t0165f9b1a3dca6c254.jpg"
]
# 创建一个新的工作簿
import openpyxl
from openpyxl.utils import get_column_letter

# 创建一个新的工作簿
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Images"

# 添加表头
ws.append(["Image URL", "Image"])

# 图片URL列表


# 将图片URL写入Excel并设置为超链接
for i, url in enumerate(image_urls, start=2):
    ws[f'A{i}'] = url
    ws[f'B{i}'] = 'Image'
    ws[f'B{i}'].hyperlink = url
    ws[f'B{i}'].style = "Hyperlink"

# 调整列宽
ws.column_dimensions['A'].width = 50  # 调整A列宽度以容纳URL
ws.column_dimensions['B'].width = 20  # 调整B列宽度以容纳图片

# 保存工作簿
wb.save("images_with_urls.xlsx")

